﻿using System;
using Iot.Shared.Helper;

namespace Iot.AlarmDispose.Database.Entities;

/// <summary>
///     告警数据模型
/// </summary>
public interface IAlertsHistory<TAlertClassify> : IDbId<long>, ISoftDelete
    where TAlertClassify : class, IAlertClassify
{
    /// <summary>
    ///     告警信息Id
    /// </summary>

    public int AlertId { get; }

    /// <summary>
    ///     开始时间
    /// </summary>

    public DateTimeOffset StartTime { get; init; }

    /// <summary>
    ///     结束时间
    /// </summary>

    public DateTimeOffset? EndTime { get; set; }

    /// <summary>
    ///     告警信息
    /// </summary>
    public TAlertClassify? AlertsInformation { get; init; }
}

public record DefaultAlertsHistory
{
    protected static readonly Lazy<SnowflakeId> SnowflakeIdLazy = new();
}

public record DefaultAlertsHistory<T>(long Id) : DefaultAlertsHistory, IAlertsHistory<T>
    where T : class, IAlertClassify
{
    public DefaultAlertsHistory() : this(SnowflakeIdLazy.Value.NextId())
    {
    }

    public long Id { get; } = Id;
    public int AlertId => AlertsInformation?.Id ?? 0;
    public DateTimeOffset StartTime { get; init; }
    public DateTimeOffset? EndTime { get; set; }
    public T? AlertsInformation { get; init; }
    public bool IsDeleted { get; set; }
    public DateTime DeletedOnly { get; set; }
}